﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace TagFlo
{
    /// <summary>
    /// Interaction logic for ExportDialog.xaml
    /// </summary>
    public partial class ExportDialog : Window
    {
         ExportWorker exportWorker;
         Collection<Photo> selectedPhotos;
         Configuration config;
        public ExportDialog(ExportWorker worker, Configuration c, Collection<Photo> photos)
        {
            exportWorker = worker;
            config = c;
            selectedPhotos = photos;
            InitializeComponent();
            if (config.MaxEdge < 1)
            {
                edgeTextBox.Text = "1000";
            }
            else
            {
                edgeTextBox.Text = config.MaxEdge.ToString();
            }

            if (photos.Count > 0)
            {
                exportCountLabel.Content = photos.Count + " photos selected for export";
                exportComboBox.IsEnabled = true;
           }
            else
            {
                exportCountLabel.Content = "You need to select the photos you wish to export.";
                exportComboBox.IsEnabled = false;
            }
            if (config.FlickerToken == null)
            {
                (exportComboBox.Items[0] as ComboBoxItem).IsEnabled = false;
            }
        }

        private void exportButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                config.MaxEdge = int.Parse(edgeTextBox.Text);
            }
            catch
            {
                config.MaxEdge = 1000;
            }
            foreach (Photo p in selectedPhotos)
            {
                switch (exportComboBox.SelectedIndex)
                {
                    case 0: //Flickr export
                        exportWorker.AddFlickrExport(p,config.MaxEdge);
                        break;

                }

            }
            this.Close();
        }

        private void exportComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (exportComboBox.SelectedItem != null)
            {
                exportButton.IsEnabled = true;
            }
            else
            {
                exportButton.IsEnabled = false;
            }
        }
    }
}
